package com.example.ware.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.ware.model.po.*;
import com.example.ware.model.responseData.ResponseData;
import com.example.ware.service.DeclareService;
import com.example.ware.service.RecordService;
import com.example.ware.service.WareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/data")
public class DataController {

    @Resource
    RedisTemplate redisTemplate;

    @Autowired
    WareService wareService;

    @Autowired
    RecordService recordService;

    @Autowired
    DeclareService declareService;




//        仓库专员获取对应的仓库数据
    @GetMapping("/one")
    public ResponseData getOne(@RequestHeader String token){
        Admin admin = (Admin)redisTemplate.opsForValue().get("Admin_" + token);


        String wid=admin.getWid();
//        获取一对应的仓库数据
        Ware ware=wareService.getById(wid);

//        获取待审核请求
        QueryWrapper<Declares> qw=new QueryWrapper<>();
        qw.eq("wid",wid).eq("status",0);
        List<Declares> awaitList=declareService.list(qw);

//       获取所有的通过请求
        QueryWrapper<Declares> qw1=new QueryWrapper<>();
        qw1.eq("wid",wid).eq("status",1);
        List<Declares> passList=declareService.list(qw1);


//        查询进出的次数
        QueryWrapper<Record> qw2=new QueryWrapper<>();
        qw2.eq("wid",wid);
        List<Record> records=recordService.list(qw2);


//        放入参数
        Map<String, Object> keyValueMap = new HashMap<>();

        keyValueMap.put("record",records.size());
        keyValueMap.put("pass",passList.size());
        keyValueMap.put("await",awaitList.size());
        keyValueMap.put("ware",ware);


        return new ResponseData(keyValueMap, true, "申请成功", 200);
    }



}
